package com.wang;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;

/**
 * @ProjectName: untitled
 * @Titile: HashSetDemo
 * @Author: 王亦凡1
 * @Description: TODO
 */
public class HashSetDemo {
    public static void main(String[] args) {

        ArrayList<String>list=new ArrayList<>();
        list.add("王彪");
        list.add("王彪");
        list.add("王彪");
        list.add("王彪");
        System.out.println(list);
        System.out.println(new HashSet<String>(list));


        HashSet<String>hashSet=new HashSet<>();
        hashSet.add("王彪");
        hashSet.add("张博文");
        hashSet.add("Mer");
        hashSet.add("刘南杉");
        hashSet.add("杨鹏");
        System.out.println(hashSet);

        //取数据（迭代器）
        Iterator<String>iterator=hashSet.iterator();
        while (iterator.hasNext()){
            String next=iterator.next();
            System.out.println(next);
        }
        //for(int i=0;i<hashset.size();i++){}无索引用不了for循环
        //取数据（增强for循环）
        for (String name:hashSet){
            System.out.println("name"+name);
        }
        int[] arr={1,2,3,4,5,6,7};
        for (int i:arr) {
            System.out.println(i);
        }
        //取数据(lambda表达式）
        hashSet.forEach (s -> System.out.println(s));

        hashSet.forEach (System.out::println);

        Student student=new Student();


    }
}
